package dk.dashboardFP.utils {

	public class Range
	{
		private var nMin:Number
		private var nMax:Number
		
		public function Range(nMin:Number, nMax:Number) {
			
			this.nMin=nMin
			this.nMax=nMax
		}
		
		public function getPosition(nRate:Number):Number {
			
			return getPositionInRange(nMin, nMax, nRate)
		}
		
		public function getRate(nPosition:Number):Number {
			return getRateInRange(nMin, nMax, nPosition)
		}
		
		//static functions////////////
		public static function getPositionInRange(nMin:Number, nMax:Number, nRate:Number):Number {
			return nMin+(nRate/(1/(nMax-nMin)));
		}
		public static function getRateInRange(nMin:Number, nMax:Number, nPosition:Number, bConstrainNumbers:Boolean=true):Number {
			var nRateInRange:Number= (nPosition-nMin)*(1/(nMax-nMin))
			
			if (bConstrainNumbers) {
				if (nRateInRange>1) {
					return 1;
				} else if (nRateInRange<0) {
					return 0;
				}
			}
			return nRateInRange;
		}
		
		
		//getter setters
		//getters
		public function get nMaxPosition():Number {
			return nMax
		}
		public function get nMinPosition():Number {
			return nMin
		}
		
		//setters
		public function set nMaxPosition(nMax:Number):void {
			this.nMax=nMax
		}
		public function set nMinPosition(nMin:Number):void {
			this.nMin=nMin
		}				public static function inRateBounds(nNumber : Number) : Number {
			if (nNumber>1) {
				return 1
			} else if (nNumber<0) {
				return 0
			}
			return nNumber
		}		
	}
}